package app.qrcode.browser.hearttoheart.activities

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import app.qrcode.browser.hearttoheart.R
import app.qrcode.browser.hearttoheart.adapters.Images
import app.qrcode.browser.hearttoheart.adapters.ImagesRVAdapter
import app.qrcode.browser.hearttoheart.databinding.ActivityMyResourseBinding

class MyResourseActivity : AppCompatActivity() {

    private val resourceAdapter by lazy { ImagesRVAdapter() }

    private val resourceList = ArrayList<Images>()

    private lateinit var binding: ActivityMyResourseBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMyResourseBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initRecyclerview()
    }


    fun replace(fragment: Fragment) {
        val fragmentManager = supportFragmentManager
        val transaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.resourse_rv, fragment)
        transaction.commit()
    }

    private fun initRecyclerview() {
        val resourceLayoutManager =
            StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        binding.resourseRv.layoutManager = resourceLayoutManager
        binding.resourseRv.adapter = resourceAdapter
        resourceList.add(Images(R.mipmap.kejian1))
        resourceList.add(Images(R.mipmap.kejian2))
        resourceList.add(Images(R.mipmap.kejian3))
        resourceList.add(Images(R.mipmap.kejian4))
        resourceList.add(Images(R.mipmap.kejian5))
        resourceList.add(Images(R.mipmap.kejian6))
        resourceList.add(Images(R.mipmap.kejian7))
        resourceList.add(Images(R.mipmap.kejian8))
        resourceList.add(Images(R.mipmap.kejian9))
        resourceList.add(Images(R.mipmap.kejian10))
        resourceList.add(Images(R.mipmap.kejian11))
        resourceList.add(Images(R.mipmap.kejianmore))
        resourceAdapter.updateList(resourceList)
    }
}